// 153. 寻找旋转排序数组中的最小值
package Leetcode_Second_Brush;

public class Solution153 {
    public int findMin(int[] nums) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (mid + 1 < nums.length && nums[mid] > nums[mid + 1])
                return nums[mid + 1];
            else if (mid - 1 >= 0 && nums[mid] < nums[mid - 1])
                return nums[mid];
            else if (nums[mid] > nums[0])
                left = mid + 1;
            else
                right = mid;
        }
        return nums[0];
    }
}
